<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/login/login.css" />
	<style>

	</style>
</head>

<body class="login">
	<div class="hide"></div>
	<div class="logoBox">
		<img src=""
						alt="logo" />
	</div>


	<div class="content">
		<div class="login-username">
			<input type="text" placeholder="请输入用户名" id="loginUser" name="loginUser" value="" onBlur="if(this.value == ''){this.type='text';value=defaultValue;}" onFocus="if(this.value == defaultValue){this.value = '';this.type='text';}" />
			<span id="message"></span>
		</div>
		<div class="login-password">
			<input id="passWord" type="password" name="password" placeholder="请输入密码" />
			<span id="pmessage"></span>
		</div>
		<!--<div class="login-checkuser">
				 <select id="checkUser" name="checkUser">
				    <option value="">请选择所属智能单元</option>
				    <option value="DJCX">大件成型智能单元</option>
					<option value="XJCX">小件成型智能单元</option>
					<option value="DJSCL">大件砂处理智能单元</option>
					<option value="XJSCL">小件砂处理智能单元</option>
					<option value="DJJZ">大件精整智能单元</option>
					<option value="XJJZ">小件精整智能单元</option>
					<option value="DJRL">大件熔炼智能单元</option>
					<option value="XJRL">小件熔炼智能单元</option>
					<option value="LXRL">离心熔炼智能单元</option>
					<!--<option value="2"></option>-->
		<!--</select>
				<span>请选择所属单元</span>-->
		<!--<a id="register">注册</a>-->
		<!--</div>-->
		<div class="login-keep">
			<!--<span>请选择所属单元</span>-->
			<input type="checkbox" id="remember-me">
			<label>保持登录</label>
			<!--<a id="register">注册</a>-->
		</div>
		<div class="login-btn">
			<button id="loginBtn" type="button" name="loginBtn" value="登录">登&nbsp;录</button>
		</div>

	</div>

</body>
<script type="text/javascript" src="../script/public/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/core/core.js"></script>
<script type="text/javascript">
	apiready = function() {
		var userName = api.pageParam.userName;
		var password = api.pageParam.password;
		var isSign = api.pageParam.isSign;
		if (isSign == '0') {
			$("#loginUser").val(userName);
			$("#passWord").val(password);
			$("#remember-me").attr("checked", true);
		}
		exitApp();

		$("#loginBtn").click(function() {

			var username = $("#loginUser").val();
			var pass = $("#passWord").val();
			var keepLogin = $('#remember-me').is(':checked');
			var checkuser = $("#checkUser").val();
			//alert(keepLogin);
			if (username == '' || username == undefined || username == null) {
				//$("#message").html("请输入账号！");
				alert('请输入账号！');
				return false;
			} else if (pass == '' || pass == undefined || pass == null) {

				//$("#pmessage").html("请输入密码！");
				alert('请输入密码！');
				return false;
			} else {
				ajaxLocal({
					userName: username,
					password: pass,
					checkuser: checkuser
				}, 'user', 'loginApp', function(ret, err) {
					//alert("登陆成功!!"+JSON.stringify(ret));
					if (ret.success) {

						$api.setStorage("user", ret.user);
						//$api.setStorage("roleName",ret.roleName);
						$api.setStorage("keepLogin", keepLogin);
						//$api.setStorage("isCheck",checkuser);

						api.openWin({
							name: 'inventory',
							url: 'win_inventory.html',
							reload: true,
							rect: {
								x: 0,
								y: 0,
								w: 'auto',
								h: 'auto'
							}
						});

						api.closeWin({
							name: 'login'
						});

					} else {
						//$("#message").html("用户已存在！");
						alert("用户名或密码错误！");
						//return false;
					}
				});
			}
		});
	};
	$("#register").click(function() {

		api.openFrame({
			name: 'register',
			url: 'register.html',
			rect: {
				x: 0,
				y: 0,
				w: 'auto',
				h: 'auto'
			}
		});
		//      api.closeFrame({
		//      });
	});

	function exitApp() {
		api.addEventListener({
			name: 'keyback'
		}, function(ret, err) {
			api.toast({
				msg: '再按一次返回键退出' + api.appName,
				duration: 2000,
				location: 'bottom'
			})
			api.addEventListener({
				name: 'keyback'
			}, function(ret, err) {
				api.closeWidget({
					id: 'A6057658489882', //这里改成自己的应用ID
					retData: {
						name: 'closeWidget'
					},
					silent: true
				});
			});

			setTimeout(function() {
				exitApp();
			}, 3000)
		});
	}
</script>

</html>
